#include "stdafx.h"
#include "movingobject.h"
#include <math.h>

static const float FLOAT_2PI = 2.0f * 3.1415f;

MovingObject::MovingObject()
{
}

MovingObject::MovingObject(const vec2f &position, float direction) :
    SceneObject(position),
    _speed(0),
    _direction(direction)
{
}

MovingObject::~MovingObject()
{
}

float MovingObject::speed() const
{
    return _speed;
}

float MovingObject::direction() const
{
    return _direction;
}

float MovingObject::speedX() const
{
    return _speed * cos(_direction);
}

float MovingObject::speedY() const
{
    return _speed * (-sin(_direction));
}

void MovingObject::setSpeed(float speed)
{
    _speed = speed;
}

void MovingObject::setDirection(float direction)
{
    if (direction < 0) {
        direction += ceil(-direction / FLOAT_2PI) * FLOAT_2PI;
    } else {
        direction -= floor(direction / FLOAT_2PI) * FLOAT_2PI;
    }
    _direction = direction;
}
